package com.ts.main.mini.controller;
import com.ts.main.mini.dto.OrderDto;
import com.ts.main.mini.dto.OrderPageSearchDto;
import com.ts.main.mini.dto.OrderSearchDto;
import com.ts.main.mini.exception.R;
import com.ts.main.mini.exception.RPage;
import com.ts.main.mini.service.OrderServiceImpl;
import com.ts.main.mini.vo.OrderDetailsVo;
import com.ts.main.mini.vo.OrderVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序-订单管理
 * @Author:lk
 * @Date: 2025/5/18  17:14
 */
@AllArgsConstructor
@RestController
@RequestMapping("/mini/order")
@Tag(name = "小程序-订单管理")
public class OrderController {

    private final OrderServiceImpl orderService;

    /**
     * 查询订单列表（分页查询）
     * @return
     */
    @Operation(summary = "查询订单列表（分页查询）")
    @PostMapping("/getOrderPage")
    public RPage<List<OrderVo>> getOrderPage(@RequestBody OrderPageSearchDto dto){
        return orderService.getOrderPage(dto);
    }

    /**
     * 查询订单列表
     * @return
     */
    @Operation(summary = "查询订单列表")
    @PostMapping("/getOrderList")
    public R<List<OrderVo>> getOrderList(@RequestBody OrderSearchDto dto){
        return R.ok(orderService.getOrderList(dto));
    }

    /**
     * 查询订单详情
     * @return
     */
    @Operation(summary = "查询订单详情")
    @GetMapping("/getOrderDetails")
    public R<OrderDetailsVo> getOrderDetails(@Schema(description = "订单ID") @RequestParam("orderId") Integer orderId){
        return R.ok(orderService.getOrderDetails(orderId));
    }


    /**
     * 查询订单状态
     * @return
     */
    @Operation(summary = "查询订单状态")
    @GetMapping("/getOrderStatus")
    public R<String> getOrderStatus(@Schema(description = "订单ID") @RequestParam("orderId") Integer orderId){
        return R.ok(orderService.getOrderStatus(orderId));
    }

    /**
     * 新增订单
     * @return
     */
    @Operation(summary = "新增订单")
    @PostMapping("/saveOrder")
    public R<String> saveOrder(@RequestBody OrderDto dto){
        return R.ok(orderService.saveOrder(dto));
    }

    /**
     * 取消订单
     * @return
     */
    @Operation(summary = "取消订单")
    @DeleteMapping("/cancelOrder")
    public R<Boolean> cancelOrder(@Schema(description = "订单ID") @RequestParam("orderId") Integer orderId){
        return R.ok(orderService.cancelOrder(orderId));
    }

    /**
     * 确认收货
     * @return
     */
    @Operation(summary = "确认收货")
    @GetMapping("/confirmOrder")
    public R<Boolean> confirmOrder(@Schema(description = "订单ID") @RequestParam("orderId") Integer orderId){
        return R.ok(orderService.confirmOrder(orderId));
    }

}
